﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpdateHands : MonoBehaviour
{
	public GameObject LShoulder;
	public GameObject RShoulder;
	public float LeftShoulderZ;
	public float RightShoulderZ;
	public Transform LeftHand;
	public Transform RightHand;
	Vector3 leftHandOffset;
	Vector3 rightHandOffset;
	// Start is called before the first frame update
	void Start()
	{
		leftHandOffset = new Vector3(-0.4f, -0.9f, 0.0f);
		rightHandOffset = new Vector3(0.4f, -0.9f, 0.0f);
		LeftShoulderZ = LShoulder.transform.rotation.eulerAngles.z;
		RightShoulderZ = RShoulder.transform.rotation.eulerAngles.z;
	}

	// Update is called once per frame
	void Update()
	{
		float angleLeft = Vector3.Angle(leftHandOffset, (LeftHand.position - LShoulder.transform.position));
		Quaternion angle = new Quaternion();
		angle.eulerAngles = new Vector3(0, 0, LeftShoulderZ - angleLeft);
		LShoulder.transform.rotation = angle;
		float angleRight = Vector3.Angle(rightHandOffset, (RightHand.position - RShoulder.transform.position));
		angle.eulerAngles = new Vector3(0, 0, RightShoulderZ + angleRight);
		RShoulder.transform.rotation = angle;
	}
}
